import api from '@/utils/api';
import { resolve } from 'path';
import { rejects } from 'assert';
const screenNav = {
    state: {
        navList:[

        ],
        navCurrentId:'',
        navVisible:false
    },
    mutations: {
        SET_NAVLIST:(state , navList)=>{
            state.navList = navList;
        },
        SET_CURRENT:(state , navCurrentId)=>{
            state.navCurrentId = navCurrentId;
        },
        SET_NAVVISIBLE:(state , navVisible) => {
            state.navVisible = navVisible;
        }
    },
    actions: {
        getNav({commit,state}){
            return new Promise((resolve,reject) => {
                api({
                    url: "topic/topicList",
                    method: "post",
                }).then(data => {
                   // console.log(data,'screen_navlist');
                    if(data.length > 0){
                        // 储存NAVLIST 主题领域列表
                        commit('SET_NAVLIST', data); 
    
                        // 存储初始化 CURRENT  默认选取第一个
                        commit('SET_CURRENT', data[0].id); 

                        resolve('获取列表成功');
                    }else{
                        
                        reject('获取列表为空');
                    }
                }).catch(err => {
                    reject(err)
                })
            })
        }
    }
}
export default screenNav;